package com.yunhe.video.controller;

import com.yunhe.common.model.ResultObject;
import com.yunhe.video.domain.ControlVideo;
import com.yunhe.video.domain.VideoResult;
import com.yunhe.video.service.IVideoService;
import org.codehaus.jettison.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;

/**
 * @Author: DongWenYu
 * @Date: 2021/3/8 13:44
 */
@RestController
@RequestMapping("/video")
public class VideoController {

    @Autowired
    IVideoService videoService;

    @PostMapping("/command/{operateVideo}")
    public ResponseEntity<ResultObject<VideoResult>> send(@PathVariable("operateVideo") String operateVideo,
                                             @RequestParam("command") String command){
        VideoResult result = videoService.sendCommand(operateVideo, command);
        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
    }

    @PostMapping("/operate/{operateVideo}")
    public ResponseEntity<ResultObject> operate(@PathVariable(value = "operateVideo", required = true) String operateVideo,
                                                @RequestParam(value = "command", required = true) String command,
                                                @RequestParam(value = "action", required = false) String action,
                                                @RequestParam(value = "speed", required = false) String speed)
                                                throws FileNotFoundException, JSONException {

        videoService.operateVideo(operateVideo, command, action, speed);
        return new ResponseEntity<>(new ResultObject<>("success"), HttpStatus.OK);
    }
}
